import Vue from 'vue'
import Router from 'vue-router'
import setTitle from '../utils/setTitle'

Vue.use(Router)

const router = new Router({
  mode: 'history',
  linkActiveClass: 'active',
  routes: [
    {
      path: '/',
      redirect: '/home'
    },
    {
      path: '/home',
      name: 'home',
      component: () => import('../views/home'),
      meta: {
        title: '木卜阁'
      }
    },
    {
      path: '/product',
      name: 'product',
      component: () => import('../views/product')
    },
    {
      path: '/orders',
      name: 'orders',
      component: () => import('../views/orders'),
      meta: {
        title: '我的订单'
      }
    },
    {
      path: '/uc',
      name: 'uc',
      component: () => import('../views/uc'),
      meta: {
        title: '个人中心'
      }
    },
    {
      path: '/discover',
      name: 'discover',
      component: () => import('../views/discover'),
      meta: {
        title: '发现'
      }
    },
    {
      path: '/cart',
      name: 'cart',
      component: () => import('../views/cart'),
      meta: {
        title: '购物车'
      }
    },
    {
      path: '/sign-in',
      name: 'signIn',
      component: () => import('../views/sign-in'),
      meta: {
        title: '登录'
      }
    },
    {
      path: '/sign-up',
      name: 'signUp',
      component: () => import('../views/sign-up'),
      meta: {
        title: '注册'
      }
    },
    {
      path: '/reset',
      redirect: '/reset/verify',
      meta: {
        title: '找回密码'
      }
    },
    {
      path: '/reset/verify',
      component: () => import('../views/reset/verify'),
      meta: {
        title: '验证身份'
      }
    },
    {
      path: '/reset/recover',
      component: () => import('../views/reset/recover'),
      meta: {
        title: '重置密码'
      }
    },
    {
      path: '/wallet',
      component: () => import('../views/wallet/index'),
      meta: {
        title: '余额'
      }
    },
    {
      path: '/wallet/logs',
      component: () => import('../views/wallet/logs'),
      meta: {
        title: '余额明细'
      }
    },
    {
      path: '/wallet/faq',
      component: () => import('../views/wallet/faq'),
      meta: {
        title: '常见问题'
      }
    },
    {
      path: '/terms',
      name: 'terms',
      component: () => import('../views/terms'),
      meta: {
        title: '用户服务协议'
      }
    }
  ]
})
router.afterEach(function (to) {
  const {title} = to.meta || {}
  title && setTitle(title)
})
export default router
